package com.dailywork.basepro.collect;

import com.google.common.collect.Sets;

import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SelfSetOper {

    public static void main(String[] args) {
        // 保存的位置是按照hash值存储
        Set<Integer> result =
                Stream.of(12, 11, 13, 14, 121, 111, 131, 113, 141)
                        .collect(Collectors.toCollection(Sets::newHashSet));
        result.forEach(System.out::println);
        System.out.println("*****************************");

        // TreeSet 默认按照升序排序
        result =
                Stream.of(12, 11, 13, 14, 121, 111, 131, 113, 141)
                        .sorted(Comparator.naturalOrder())
                        .collect(Collectors.toCollection(TreeSet::new));
        // 使用链表存储，默认没有排序
        LinkedHashSet<Integer> datas =
                Stream.of(12, 11, 13, 14, 121, 111, 131, 141)
                        .sorted(Comparator.reverseOrder())
                        .collect(Collectors.toCollection(LinkedHashSet::new));
        result.forEach(System.out::println);
        System.out.println("*****************************");
        datas.forEach(System.out::println);

        List<Integer> arra1 = Arrays.asList(1,2,3,4);
        List<Integer> arra2 = new LinkedList<>();
        System.out.println(arra1.containsAll(arra2));
        System.out.println(arra2.containsAll(arra1));
    }
}
